package siruna.WE.DeviceDependent.AndroidViews;

import java.util.HashMap;

import siruna.WE.core.model.VisualBlock;
import siruna.WE.core.model.VisualBlocks.ImageImpl;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;

public class ImageRenderer extends ImageView{

	public ImageRenderer(Context context, VisualBlock vb) {
		super(context);
		System.out.println("halllooooo: ImageRenderer geconstrueert");
		
		final HashMap<String, String> attributes = vb.getAttributes();

		ImageImpl vi = (ImageImpl) vb;

		if (vi.getBytes() != null) {
			System.out.println(vi.getBytes().length);
			byte[] bytes = vi.getBytes();
			Bitmap b = BitmapFactory
					.decodeByteArray(bytes, 0, bytes.length);

			System.out.println("width: " + attributes.get("width"));
			System.out.println("height: " + attributes.get("height"));

			if (attributes.get("width") != null
					&& attributes.get("height") != null) {
				System.out.println("hoogte en breedte opegegeven");
				int w = Integer.parseInt(attributes.get("width"));
				int h = Integer.parseInt(attributes.get("height"));

				b = b.createScaledBitmap(b, w, h, true);
			}

			setImageBitmap(b);
		}

		
		
		
	}

	
	
	
	
	
}
